import {storageSession} from '@/storage'
import {ApiGetRulesList,ApiGetRiskRules} from '@/api/index'
const state ={
    allrules:storageSession.getItem('allrules')?storageSession.getItem('allrules'):[],
    activityrules:storageSession.getItem('activityrules')?storageSession.getItem('activityrules'):[]
}
const mutations ={
    SET_ALLRULES:(state,data)=>{
          state.allrules = data
          storageSession.setItem('allrules',data)
    },
    SET_ACTIVITYRULES:(state,data)=>{
        state.activityrules = data
        storageSession.setItem('activityrules',data)
    }
}
const actions = {
    asyncSetAllRules:async ({commit})=>{   
        const {data:res} = await ApiGetRiskRules() as Record<string,any> 
            commit('SET_ALLRULES',res)
    },
    asyncSetActivityRules:async ({commit})=>{
        const {data:res} = await ApiGetRulesList() as Record<string,any>
        commit('SET_ACTIVITYRULES',res)
    }
}
export default {
    namespaced:true,
    state,
    mutations,
    actions
}